package com.acme.bankapp.service.bank;

import com.acme.bankapp.domain.bank.Account;
import com.acme.bankapp.domain.bank.Bank;
import com.acme.bankapp.domain.bank.Client;

import java.util.Random;

public class BankService {
    public void addClient(Bank bank, Client client) throws ClientExistsException {
        bank.addClient(client);
    }

    public void printBalance(Bank bank) {
        for (Client client : bank.getClients()) {
            System.out.println(client.getClientSalutation());
            for (Account account : client.getAccounts()) {
                System.out.println(String.format("\t%s balance: %s", account.getClass().getName(), account.getBalance()));
            }
        }
    }

    public void printMaximumAmountToWithdraw(Bank bank) {
        for (Client client : bank.getClients()) {
            System.out.println(client.getClientSalutation());
            for (Account account : client.getAccounts()) {
                System.out.println(String.format("\t%s: %s", account.getClass().getSimpleName(), account.maximumAmountToWithdraw()));
            }
        }
    }

    public void modifyBank(Bank bank) throws NotEnoughFundsException {
        Random random = new Random();
        for (Client client : bank.getClients()) {
            for (Account account : client.getAccounts()) {
                account.withdraw(random.nextInt(100));
                account.deposit(random.nextInt(100));
            }
        }
    }
}